package com.tskj.leonsu.controller;

import com.alibaba.fastjson.JSONObject;
import com.tskj.leonsu.aop.annotation.SystemControllerLog;
import com.tskj.leonsu.service.BathRoomService;
import com.tskj.leonsu.service.HairCutService;
import com.tskj.leonsu.service.LoginService;
import com.tskj.leonsu.service.StudentService;
import com.tskj.leonsu.utility.Tools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 理发服务
 * @author LeonSu
 */
@Controller
@RequestMapping("/haircut")
public class HairCutController {

    @Autowired
    private HairCutService hairCutService;

    @Autowired
    private LoginService loginService;

    @Autowired
    private StudentService studentService;

    /**
     * 获取理发店列表
     * @return
     */
    @GetMapping("/list")
    @ResponseBody
    public JSONObject getList() {
        JSONObject ret = new JSONObject();
        ret.put("code", 0);
        ret.put("data", hairCutService.getBathRoomList());
        return ret;
    }

    /**
     * 获取理发时间表
     * @param hairCutId
     * @param date
     * @return
     */
    @GetMapping("/timeList")
    @ResponseBody
    public JSONObject getTimeList(@RequestParam String hairCutId, @RequestParam String date) {
        JSONObject ret = new JSONObject();
        ret.put("code", 0);
        ret.put("data", hairCutService.getTimeList(hairCutId, date));
        return ret;
    }

    /**
     * 保存理发订单
     * @param data
     * @return
     */
    @PostMapping("/save")
    @ResponseBody
    public JSONObject saveOrder(@RequestParam String token, @RequestBody JSONObject data) {
        String adUserName = loginService.getAdUserName(token);
        JSONObject student = studentService.getStudentInfo(adUserName);
        return hairCutService.saveOrder(student, data);
    }

    @GetMapping("/checkStopTime")
    @ResponseBody
    public JSONObject checkStopTime(@RequestParam String token) {
        String adUserName = loginService.getAdUserName(token);
        return hairCutService.checkStopTime(adUserName, Tools.today());
    }

}
